package com.basic.modules.nykf.controller;

import com.basic.common.utils.R;
import com.basic.modules.nykf.entity.FileNewEntity;
import com.basic.modules.nykf.service.FileNewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("new/ykf/fileNew")
public class FileNewController {

    @Autowired
    FileNewService fileNewService;

    /**
     * 根据业务的关联id查询出附件列表
     *
     * @param fileNewEntity
     * @return
     */
    @PostMapping("/getFileListByGlId")
    public R getFileListByGlId(@RequestBody FileNewEntity fileNewEntity) {
        List<FileNewEntity> fileListByGlId = fileNewService.getFileListByGlId(fileNewEntity);
        return R.ok(fileListByGlId);
    }

    /**
     * 上传附件
     *
     * @param file
     * @param map
     * @return
     */
    @PostMapping("/uploadFile")
    public R uploadFile(@RequestParam("file") MultipartFile file, @RequestParam Map map) {
        return fileNewService.uploadFile(file, map);
    }

    /**
     * 删除文件
     *
     * @param fileNewEntity
     * @return
     */
    @PostMapping("/postDeleteFile")
    public R postDeleteFile(@RequestBody FileNewEntity fileNewEntity) {
        return R.ok(fileNewService.postDeleteFile(fileNewEntity));
    }

    /**
     * 下载文件
     *
     * @param fileNewEntity
     * @return
     */
    @PostMapping("/postDownLoadFile")
    public R postDownLoadFile(@RequestBody FileNewEntity fileNewEntity) {
        return R.ok(fileNewService.postDownLoadFile(fileNewEntity));
    }
}